<?php
class CompareController extends AppController 
{	
	public function index()
	{
		$this->view->title = '虾比网 - 什么是最好?比过才知道';
		$this->view->show();
	}
	
	public function addKeyword()
	{
		$kw = new KeywordModel();
		$kw->add(array('word' => P('kw'), 'user_id' => $this->user->id));
		$this->view->json(array('msg' => '关键词已经保存', 'id' => $kw->lastId));
	}
	
	public function addItem()
	{
		$item = new ItemModel();
		$itemNames = explode(",", P('itemNames'));
		foreach($itemNames as $itemName){
			$item->add(array('name' => $itemName, 'user_id' => $this->user->id, 'keyword_id' => p('keywordId')));
		}
		$this->view->json(array('msg' => '已经保存比较项'));
	}
	
	public function addObj()
	{
		$obj = new ObjModel();
		$objNames = explode(",", p('objNames'));
		foreach($objNames as $objName){
			$obj->add(array('name' => $objName, 'user_id' => $this->user->id, 'keyword_id' => p('keywordId')));
		}
		$this->view->json(array('msg' => '已经保存比较对象'));
	}
	
	public function add()
	{
		$this->addKeyword();
	}
}
